#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    //先获取两个DateTimeEdit的日期时间
    QDateTime timeOld = ui->dateTimeEdit->dateTime();
    QDateTime timeNew = ui->dateTimeEdit_2->dateTime();

    qDebug() << timeOld << timeNew;

    //计算日期和时间的差值
    int seconds = timeOld.secsTo(timeNew);	//计算两个日期时间相差的秒数
    int hours = (seconds / 3600) % 24;
    int days =  (seconds / 3600) / 24;

    ui->label->setText(QString("相差:") + QString::number(days) + "天" + QString::number(hours) + "小时");
}
